package com.kernel.enums;

/****************************************
 * @name Color
 * @description
 * @author 黄彬恒
 * @since 2018/8/22
 ***************************************/
public enum Color {
    RED("红色"), GREEN("绿色"), BLUE("蓝色"); // 定义三个枚举的类型(为每个枚举类型给予特殊的标识描述)

    private String name;

    Color(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    /**
     * @param name 通过set方法设定每个枚举元素的标识
     */
    public void setName(String name) {
        switch (this) {
            case RED:
                if ("红色".equals(name)) {
                    this.name = name;
                } else {
                    System.out.println("unknown error");
                }
                break;
            case GREEN:
                if ("绿色".equals(name)) {
                    this.name = name;
                } else {
                    System.out.println("unknown error");
                }
                break;
            case BLUE:
                if ("蓝色".equals(name)) {
                    this.name = name;
                } else {
                    System.out.println("unknown error");
                }
                break;
        }
    }
}
